#ifndef CL_CHECK_H
#define CL_CHECK_H

#ifdef _WIN32
    #define CL_CALL __cdecl
    #define CL_API __declspec(dllexport)
#else
    #define CL_CALL
    #define CL_API
#endif

#ifdef __APPLE__
    #include <OpenCL/opencl.h>
#else
    #include <CL/cl.h>
    #include <CL/cl_ext.h>
#endif

#include "clFFT.h"
#include "clBLAS.h"

CL_API int CL_CALL check_cl_error (cl_int cl_err, int line,
                                   const char *func_name);
CL_API int CL_CALL check_cl_error (clfftStatus cl_err, int line,
                                   const char *func_name);
CL_API int CL_CALL check_cl_error (clblasStatus cl_err, int line,
                                   const char *func_name);

class ClException{};

#define _PERF_CHECK_CL_ERROR_INNER(cond, func, line)                           \
    do                                                                         \
    {                                                                          \
        if (check_cl_error (cond, line, func))                                 \
            throw ClException();                                               \
    }                                                                          \
    while (0)

#define CHECK_CL_ERROR(cond) _PERF_CHECK_CL_ERROR_INNER(cond, __PRETTY_FUNCTION__, __LINE__)

#endif
